<?php
$objXajax->registerFunction("frmreportlistbookroom_search");
$objXajax->registerFunction("frmreportlistbookroom_init");
  
 function  frmreportlistbookroom_init(){
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax      
    $fromdate = SYSTEM_DATE;  
    $todate = SYSTEM_DATE; 
    $objResponse->addScript("$('#frmreportlistbookroom_fromdate').val('$fromdate')"); 
    $objResponse->addScript("$('#frmreportlistbookroom_todate').val('$todate')");     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax           
 }

function frmreportlistbookroom_search($params){
    global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax  
    $arrData = frmreportlistbookroom_createArray($params);
    $arrData = array();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/hotel_reportlistbookroom_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('frmreportlistbookroom_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmreportlistbookroom_tbl');");  
    $objResponse->addScript('changeWaiting(1);');                     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function frmreportlistbookroom_createArray($params){
    global $objDbUpdate,$tbl_postfix;

    $regist1=$params['regist1'] ;
    $regist2=$params['regist2'] ;
    $to1=$params['to1'] ;
    $to2=$params['to2'] ;
    $go1=$params['go1'] ;
    $go2=$params['go2'] ;

    $condtion =  " WHERE  1 = 1 ";
    if($params['noview']==0||$params['noprocess']==0||$params['process']==0){
        $condtion .=' AND (1=2 ';  
        if($params['noview']==1){
           $condtion.= ' OR flg_process == 0'; 
        }
        if($params['noprocess']==1){
           $condtion.= ' OR flg_process == 1'; 
        }
        if($params['process']==1){
           $condtion.= ' OR flg_process == 2'; 
        }
        $condtion.=')';
    }
    
    if($regist1!=''){
      $condtion .= " and b.date_created >= '$regist1' ";  
    }
    if($regist2!=''){
      $condtion .= " and b.date_created <= '$regist2' ";  
    }
    if($to1!=''){
      $condtion .= " and b.date_start >= '$to1' ";  
    }
    if($to2!=''){
      $condtion .= " and b.date_start <= '$to2' ";  
    }
    if($go1!=''){
      $condtion .= " and b.date_checkout >= '$go1' ";  
    }
    if($go2!=''){
      $condtion .= " and b.date_checkout <= '$go2' ";  
    }

    $sql = " select b.*,r.name as roomtype from tbl_customer_book_room$tbl_postfix as b left join tbl_room_type$tbl_postfix r ON b.room_type_id = r.id $condtion order by b.date_checkout ";//
    $arr = $objDbUpdate->GetArray($sql);    
   // echo $sql; die();
    return  $arr  ;
} 

# end region process data
?>
